package com.example.springboot.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.common.Result;
import com.example.springboot.controller.dto.FollowDTO;
import com.example.springboot.controller.dto.LikesDTO;
import com.example.springboot.entity.Follows;
import com.example.springboot.entity.Likes;
import com.example.springboot.mapper.LikesMapper;
import com.example.springboot.service.ILikesService;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * <p>
 * 点赞表 API控制器 - 不需要token验证的API
 * </p>
 *
 * @author
 */
@RestController
@RequestMapping("api/likes")
public class LikesApi {
    @Resource
    private ILikesService iLikesService;

    @Resource
    private LikesMapper likesMapper;

    //个人主页点赞列表
    @GetMapping("/page")
    public Result personalPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam String userId) {

        // 构造分页和排序条件
        Page<LikesDTO> pageInfo = new Page<>(page, pageSize);
        QueryWrapper<Likes> queryWrapper = new QueryWrapper<Likes>();
        if (!" ".equals(userId)) {
            queryWrapper.eq("user_id",userId);
        }
        // 执行查询（自动关联用户表）
        Page<LikesDTO> result = iLikesService.pageWithAuthor(pageInfo, queryWrapper);
        return Result.success(result);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        likesMapper.deleteById(id);
        return Result.success();
    }
}
